extends Node

var utils = null
var ctrl = null
var base = null
var path = null
var window
var context
var file = File.new()
var elist = ["i_horse","i_horse5_Hide","i_horse5_Hide_MAX","i_horse8_Hide","i_horse8_Hide_MAX","i_horse17_Hide","i_horse17_Hide_MAX","i_horse23_Hide","i_horse23_Hide_MAX",
	"i_bangleb","i_bangleb13_Hide","i_bangleb13_Hide_MAX","i_bangleb25_Hide","i_bangleb25_Hide_MAX",
	"i_bangled","i_bangled13_Hide","i_bangled13_Hide_MAX","i_bangled25_Hide","i_bangled25_Hide_MAX",
	"i_bangleh","i_bangleh13_Hide","i_bangleh13_Hide_MAX","i_bangleh25_Hide","i_bangleh25_Hide_MAX",
	"i_TD_mitt","i_TD_mitt_Hide","","","i_TD_mitt1_Hide_MAX","","i_TD_mitt2_Hide_MAX","","i_TD_mitt3_Hide_MAX",
	"i_TD_scope","i_TD_scope1_Hide_MAX","","i_TD_scope2_Hide_MAX","","i_TD_scope3_Hide_MAX",
	"i_TD_shoe","i_TD_shoe_Hide","i_TD_shoe_Hide_MAX",
	"i_TD_core","i_TD_core_Hide","i_TD_core_Hide_MAX",
	"i_TD_pipa","i_TD_pipa_Hide_MAX",
	"i_TD_harp","i_TD_harp_Hide_MAX",
	"i_TD_key","i_TD_key_Hide_MAX",
	"i_TD_accordion",
	"i_TD_coin",
	"i_TD_drum",
	"i_TD_flute",
	"i_TD_horn",
	"i_TD_spell"
]
var xlist = ["i_horse","i_bangleb","i_bangled","i_bangleh","i_TD_scope","i_TD_mitt"]
func _ready():
	pass
func _init():
	call_deferred("init")
func init():
	if globalData.infoDs.has("g_AneHekBase"):
		base = globalData.infoDs["g_AneHekBase"]
		path = chaData.infoDs["cTDW"].dir
	if base != null:
		#初始化
		utils = globalData.infoDs["g_AneHekUtils"]
		ctrl = globalData.infoDs["g_AneHek"]
		base.connect("onSaveGame",self,"resetData")
		#base.connect("onStartGame", self, "abc")
#重置数据
func resetData():
	if is_instance_valid(window):
		context.queue_free()
		window.queue_free()
		context = null
		window = null
#创建装备按钮
func newChaBt(node, id):
	var chaBt = preload("res://ui/item/item.tscn").instance()
	var items = sys.newItem(id)
	chaBt.init(items)
	chaBt.isDrag = false
	chaBt.rect_position = Vector2(40, 30)
	#var chaBt = utils.cTr(id + "/ico.png")
	node.add_child(chaBt)
#创建窗口
func createIllstrate():
	if window != null:return
	var baseui = sys.main.get_node("ui")
	#baseui.print_tree_pretty()
	window = utils.cWin(baseui,"塔防之光装备图鉴",Vector2(1300,500))
	var k =utils.cBtns(window,self,"帮助","showhelp",[],Vector2(10,10))
	k.set_position(Vector2(600,20))
	context = utils.cSc(window,Vector2(1200,680),Vector2(30,120))
	#context.set_size(Vector2(1240,700))
	#context.set_position(Vector2(30,60))
	var taskBox = HBoxContainer.new()
	context.add_child(taskBox)
	var pos = 0
	while pos < len(elist):
		var nid = elist[pos]
		#print(nid)
		var vbox = VBoxContainer.new()
		taskBox.add_child(vbox)
		var hBox1 = HBoxContainer.new()
		hBox1.alignment = 1
		hBox1.set_custom_minimum_size(Vector2(130, 50))
		vbox.add_child(hBox1)
		newChaBt(hBox1,nid)
		var cnt = 0
		pos += 1
		if pos >= len(elist):break
		if xlist.find(nid) != -1:
			utils.cBtns(vbox,self,"合成详情","show",[nid],Vector2(100,40))
		else:
			hBox1.set_custom_minimum_size(Vector2(130, 105))
		var hBox24 = HBoxContainer.new()
		hBox24.alignment = 1
		vbox.add_child(hBox24)
		#2-4分容器
		var vBox3 = VBoxContainer.new()
		vBox3.alignment = 1
		hBox24.add_child(vBox3)
		#2级单位容器
		var hBox2 = HBoxContainer.new()
		hBox2.alignment = 1
		hBox2.set_custom_minimum_size(Vector2(130, 100))
		vBox3.add_child(hBox2)
		#3级单位总容器
		var hBox33 = HBoxContainer.new()
		hBox33.alignment = 1
		vBox3.add_child(hBox33)
		#3-4级单位分容器
		var vBox34 = VBoxContainer.new()
		vBox34.alignment = 1
		hBox33.add_child(vBox34)	
		#3级单位容器
		var hBox3 = HBoxContainer.new()
		hBox3.alignment = 1
		hBox3.set_custom_minimum_size(Vector2(130, 100))
		vBox34.add_child(hBox3)
		while elist[pos].find(nid) != -1 || elist[pos] == "":
			if elist[pos] == "":
				pos += 1
				cnt += 1
				continue
			if cnt == 2:
				cnt = 0
			if cnt:
				newChaBt(hBox3,elist[pos])
			else:
				newChaBt(hBox2,elist[pos])
			pos += 1
			cnt += 1
func showhelp():
	sys.newBaseMsg("帮助","装备有进化的，可以用材料进行进化，若分支只有一个，则所有材料都会进化为该分支，且材料决定进化分支是1级升2级，2级升3级使用任意材料即可；多分支则可以点击合成详情进行查看何种材料进化为何种分支")
func openit():
	window.popup_centered() 
func show(id):
	var tr = utils.cTr("test/"+id+".png")
	window.add_child(tr)
	tr.set_position(Vector2(300,20))
	utils.cBtns(tr,self,"确定","close",[tr],Vector2(285,450))
func close(k):
	k.queue_free()